import store from "@/store"
import CButton from "../../../custom-components/CButton/attr"
import CDatePicker from "../../../custom-components/CDatePicker/attr"
import CRangePicker from "../../../custom-components/CRangePicker/attr"
import CSelect from "../../../custom-components/CSelect/attr"
import CTabs from "../../../custom-components/CTabs/attr"
import CCustom from "../../../custom-components/CCustom/attr"

const common = [
  {
    type: "input",
    label: "默认值",
    fieldName: "value",
    initialValue: "",
    extraConfig: {
      className: "row",
    }
  },
]

export default function getAttrList(tag, lowCode, vm){
  let list; let isNoCommon
  switch(tag) {
    case "c-button":
      list = CButton.attr({})
      isNoCommon = true
      break
    case "c-date-picker":
      const {dateFilterFieldList} = lowCode
      list = CDatePicker.attr({dateFilterFieldList, props: store.state.lowCode.selectedComponent.props})
      break
    case "c-range-picker":
      const rangeDateFilterFieldList = lowCode.dateFilterFieldList
      list = CRangePicker.attr({dateFilterFieldList: rangeDateFilterFieldList, props: store.state.lowCode.selectedComponent.props})
      break
    case "c-select":
      const {
        selectFilterFieldList,
        selectFilterFieldOptions
      } = lowCode
      list = CSelect.attr({selectFilterFieldList, selectFilterFieldOptions})
      break
    case "c-tabs":
      const tabList = store.state.lowCode.selectedComponent.props.list || []
      list = CTabs.attr({tabList})
      break
    case "c-custom":
      const customList = store.state.lowCode.selectedComponent.props.list || []
      list = CCustom.attr({customList})
      break
    default:
      list = []
  }
  const init = []
  if(!isNoCommon){
    common.forEach(commonItem => {
      const value = list.find(item => item.fieldName === commonItem.fieldName)
      if(!value){
        init.push(commonItem)
      }
    })
  }


  return [...init, ...list]
}
